﻿@{
    ViewData["Title"] = "{$table.remark}";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div white-bg">
    <div class="ibox-content">
        <form class="form-horizontal m" id="dataForm" autocomplete="off">
            <input type="hidden" id="id" name="id" value="@(ViewBag.Id)">
            <vt:foreach from="$#.columns" item="column" index="#.i">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">{$:#.column.comment}：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="{$:#.column.column_name}" id="{$:#.column.column_name}" data-rule="required">
                    </div>
                </div>
            </vt:foreach>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" id="remark" cols="60" rows="4"></textarea>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="footerbar">
                <div class="col-sm-12 col-sm-offset-4">
                    <button class="btn btn-primary" type="submit">
                        <i class="fa fa-check"></i>
                        保存
                    </button>
                    <button class="btn btn-danger" type="button" onclick="cancel()">
                        <i class="fa fa-reply-all"></i>关闭
                    </button>
                </div>
            </div>
        </form>

    </div>
</div>
@section scripts{
<script type="text/javascript">
    $(function () {
        $('#dataForm').validator({
            stopOnError: false,
            timely: 2,
            theme: "yellow_right",
            valid: function (form) {
                //console.log(form);
                jutils.ajaxPost("/admin/{$upperTableName}/SaveData", $(form).serialize(), function (res) {
                    if (res.status) {
                        cancel();
                    }
                });
            },
        });
        loadModel();
    });
    function loadModel() {
        let id = $('#id').val();
        if (jutils.emptyId(id)) {
            return;
        }
        jutils.ajaxGet('/admin/{$upperTableName}/getmodel', { id: id }, function (res) {
            // console.log(res);
            if (res.status) {
                let model = res.data.model;
                $('#dataForm').initFormData(model);
            }
        });
    }


    function cancel() {
        jutils.closeDialog();
    }

</script>
}